{{ $scripts := (site.Data.ui.scripts) }}
{{ $cfg := (site.Params) }}

<!--[ vendor-external ]-->
{{ with ($scripts.vendor.external) }}
    {{ range . }}
      <script src="{{ . }}" crossorigin="anonymous" defer></script>
    {{ end }}
{{ end }}
<!--[ / vendor-external ]-->

<!--[ vendor-internal ]-->
{{ with ($scripts.vendor.internal) }}
    {{ $bundle := slice }}
    {{ range . }}{{ $bundle = (($bundle) | append (resources.Get .)) }}{{ end }}
    {{ $bundle = (($bundle) | resources.Concat "js/vendor.bundle.js") }}
    {{ $bundle = ((($bundle) | minify) | resources.Fingerprint) }}
    <script src="{{ ($bundle.RelPermalink) }}" integrity="{{ ($bundle.Data.Integrity) }}"
            crossorigin="anonymous" defer></script>
{{ end }}
<!--[ / vendor-internal ]-->

<!--[ system-internal ]-->
{{ with ($scripts.system.internal) }}
    {{ $bundle := slice }}
    {{ range . }}{{ $bundle = (($bundle) | append (resources.Get .)) }}{{ end }}
    {{ $bundle = ((($bundle) | resources.Concat "js/system.bundle.js") | js.Build) }}
    {{ $bundle = (($bundle) | resources.ExecuteAsTemplate ("js/system.bundle.js" | relLangURL) .) }}
    {{ $bundle = ((($bundle) | minify) | resources.Fingerprint) }}
    <script src="{{ ($bundle.RelPermalink) }}" integrity="{{ ($bundle.Data.Integrity) }}"
            crossorigin="anonymous" defer></script>
{{ end }}
<!--[ / system-internal ]-->

<!--[ github-comments ]-->
{{ if (and ($cfg.node.tabs.comments.enabled) (.Params.comments)) }}
    {{ $cfg := (site.Params.node.tabs.comments.giscus) }}
    <script src="https://giscus.app/client.js"
            data-repo="{{ ($cfg.repo) }}"
            data-repo-id="{{ ($cfg.repo_id) }}"
            data-category="{{ ($cfg.category) }}"
            data-category-id="{{ ($cfg.category_id) }}"
            data-mapping="{{ ($cfg.mapping) }}"
            {{ if (eq ($cfg.mapping) "specific") }}
              data-term="{{ printf "%s/%s/" (site.Language.Lang) (.Page.Params.uuid) }}"
            {{ end }}
            data-strict="{{ ($cfg.strict) }}"
            data-reactions-enabled="{{ ($cfg.reactions) }}"
            data-emit-metadata="{{ ($cfg.metadata) }}"
            data-input-position="{{ ($cfg.position) }}"
            data-theme="{{ ($cfg.theme) }}"
            data-lang="{{ (site.Language.Lang) }}"
            data-loading="lazy"
            crossorigin="anonymous"
            async>
    </script>
{{ end }}
<!--[ / github-comments ]-->
